#include <stdio.h>
#include <mysql/mysql.h>

const char *user = "xzy";
const char *host = "localhost";
const char *passwd = "XKLxkl99...";
const char *db = "test_2";
unsigned int port = 3306;

int main()
{
    // 初始化
    MYSQL *mysql = mysql_init(NULL);
    if (mysql == NULL)
    {
        fprintf(stderr, "mysql_init() failed\n");
        return EXIT_FAILURE;
    }

    // 连接
    if (mysql_real_connect(mysql, host, user, passwd, db, port, NULL, 0) == NULL)
        printf("err\n");

    const char *sql = "select *from account";
   if (mysql_query(mysql,sql)!= 0)
    printf("heh\n");


    MYSQL_RES * res = mysql_store_result(mysql);
    
    int row = mysql_num_rows(res);
    int num = mysql_num_fields(res);
    //printf("%d,%d",row,num);

    MYSQL_FIELD * filed = mysql_fetch_fields(res);

    for(int i = 0; i < num; i++)
    {
        printf("%s\t",filed[i].name);
    }
    printf("\n");

    MYSQL_ROW line;
    for(int i = 0; i < row; i++)
    {
        line = mysql_fetch_row(res);
        for(int j = 0; j < num; j++)
            printf("%s\t",line[j]);
        
        printf("\n");
    }

    

    return 0;
}